#pragma once

#include "point.h"

namespace x3
{
	class Rect
	{
	public:
		Rect(): m_l(0),m_t(0),m_r(0),m_b(0) {}
		Rect( int l, int t, int r, int b ) : m_l( l ), m_t( t ), m_r( r ), m_b( b ) {}
		Rect(const Point &pt,int width,int height):m_l(pt.m_x),m_t(pt.m_y) { m_r = m_l+width; m_b = m_t+height; }

		int width() const { return abs(m_r-m_l+1); }
		int height() const { return abs(m_b - m_t + 1); }

		bool            isPointIn( int x, int y ) const { return x >= m_l && x < m_r && y >= m_t && y < m_b; }
		bool            isPointIn( const Point& pt ) const { return isPointIn( pt.m_x, pt.m_y ); }

		// operator
		bool			operator == ( const Rect& rc ) const { return (m_l==rc.m_l&&m_t==rc.m_t&&m_r==rc.m_r&&m_b==rc.m_b); }
		Rect			operator + ( const Point& pt ) const { return Rect( m_l + pt.m_x, m_t + pt.m_y, m_r + pt.m_x, m_b + pt.m_y ); }
		Rect			operator - ( const Point& pt ) const { return Rect( m_l - pt.m_x, m_t - pt.m_y, m_r - pt.m_x, m_b - pt.m_y ); }
	public:
		int m_l, m_t, m_r, m_b;
	};
}